package com.xc.stock.domain.basic.factory;

import java.math.BigDecimal;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.ag.utils.SysConstant;
import com.ag.utils.SysConstant.ProgressEnum;
import com.xc.stock.constant.AccountLogType;
import com.xc.stock.domain.basic.entity.Account;
import com.xc.stock.domain.basic.entity.AccountAction;
import com.xc.stock.dto.model.AccountOperParam;
import com.xc.stock.utils.SpringUtils;

/**
 * AccountActionFactory 
 *
 * @author xlfd 
 * @email xlfd@gmail.com 
 * @created 2022/03/25 
 */
@Component
@Lazy
public class AccountActionFactory {
	public AccountAction from(Account account, AccountLogType accountLogType, BigDecimal amount,
			AccountOperParam accountOperParam) {
		
		ProgressEnum limitWithrawStatus = ProgressEnum.SUCCESS;
		if(accountOperParam.hasLimitWithraw()) {
			limitWithrawStatus = ProgressEnum.DOING;
		}
		AccountAction e = AccountAction.builder()
				.accountId(account.getId())
				.accountNo(account.getAccountNo())
				.accountType(account.getAccountType())
				.accountCurrency(account.getCurrency())
				.agentId(accountOperParam.getAgentId())
				.agentMemberId(accountOperParam.getAgentMemberId())
				.agentMemberNo(accountOperParam.getAgentMemberNo())
				.action(accountOperParam.getAccountAction().code())
				.type(accountOperParam.getAccountAction().type())
				.amount(amount)
				.destId(account.getDestId())
				.destName(account.getDestName())
				.destPhone(account.getDestPhone())
				.logContent(accountOperParam.getLogContent())
				.ext(accountOperParam.getLogExt() == null ? "{}" : accountOperParam.getLogExt().toJSONString())
				.outerUid(accountOperParam.getOuterUid())
				.outerNo(accountOperParam.getOuterNo())
				.role(account.getRole())
				.limitWithdrawAt(accountOperParam.getLimitWithrawAt())
				.limitWithdrawStatus(limitWithrawStatus.v())
				.actionStatus(ProgressEnum.DOING.v())
				.status(SysConstant.STATUS_NORMAL)
				.build();
		
		e.putExt("stampTax", accountOperParam.getStampTax());
		e.putExt("commission", accountOperParam.getCommission());
		e.putExt("recharge", accountOperParam.getRecharge());
		e.putExt("preTradingDay", accountOperParam.getPreTradingDay());
		e.putExt("withdrawAmount", accountOperParam.getWithdrawAmount());
		e.putExt("agent", accountOperParam.getAgent());
		e.putExt("member", accountOperParam.getMember());
		return e;
	}
	
  public static AccountActionFactory of() {
    return SpringUtils.getBean(AccountActionFactory.class);
  }
}
